import requests
import OS模块
import re
# n=int(input('请输入你需要爬取的页数：'))
# for i in range(1,n+1):
headers = {

    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
}
# url='http://www.bbsnet.com/doutu/page/1'
url='http://image.baidu.com/search/index?tn=baiduimage&ct=201326592&lm=-1&cl=2&ie=gb18030&word=%CD%BC%C6%AC&fr=ala&ala=1&alatpl=adress&pos=0&hs=2&xthttps=000000'
url='http://www.bbsnet.com/doutu'
r=requests.get(url,headers=headers,timeout=5)
html=r.text
# print(html)
c=re.findall(' <img src="(.*?)"',html)
for j in c:
    # print(c)
    root='D://表情包1//'
    path=root+j.split('/')[-1]
    if not OS模块.path.exists(root):
        OS模块.mkdir(root)
    if not OS模块.path.exists(path):
        r=requests.get(c)
        with open(path,'wb') as f:
            f.write(r.content)
            f.close()